/**
 * 
 */
package fr.data.structure.pile;

import java.util.ArrayList;

/**
 * @author fred
 * 
 */
public class Pile implements PileOperation {
	private ArrayList<Object> pile;
	private static int Max_Capacity = 100;

	public Pile() {
		pile = new ArrayList<Object>();
	}

	@Override
	public int size() {
		return pile.size();
	}

	@Override
	public boolean isEmpty() {
		return (pile.size() == 0);
	}

	@Override
	public boolean isFull() {
		return (pile.size() == Max_Capacity);
	}

	@Override
	public void empiler(Object val) throws PileException {
		if (!isFull())
			pile.add(val);
		else
			throw new PileException("La pile est pleine");
	}

	@Override
	public Object depiler() throws PileException {
		if (!isEmpty()) {
			Object object = pile.get(pile.size() - 1);
			pile.remove(pile.size() - 1);
			return object;
		} else
			throw new PileException("La pile est vide");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Pile = " + pile;
	}

}
